package com.penghaisoft.microwms.product.service.impl;

import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;
import com.penghaisoft.microwms.common.wms.model.MsbarCode;
import com.penghaisoft.microwms.product.dao.MsbarCodeMapper;
import com.penghaisoft.microwms.product.service.IMsbarCodeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 业务逻辑实现类
 * </p>
 *
 * @author
 * @createDate
 **/
@Service("msbarCodeService")
public class MsbarCodeServiceImpl extends BaseService implements IMsbarCodeService {
    @Resource
    private MsbarCodeMapper msbarCodeMapper;

    /**
     * 新增记录
     *
     * @param baseResource
     * @return
     */
    @Override
    public Resp create(MsbarCode msbarCode) {
        msbarCodeMapper.create(msbarCode);
        return success();
    }

    /**
     * 删除记录（逻辑删除）
     *
     * @param baseResource
     * @return
     */
    @Override
    public Resp delete(MsbarCode msbarCode) {
        msbarCodeMapper.delete(msbarCode);
        return success();
    }

    /**
     * 查询列表
     *
     * @param pager
     * @param baseResource
     * @return
     */
    @Override
    public Pager<MsbarCode> findListByCondition(int page, int rows, MsbarCode condition) {
        Pager<MsbarCode> pager = new Pager<>();
        pager.setPage(page);
        pager.setRows(rows);
        condition.preQuery();
        long size = msbarCodeMapper.queryCount(condition);
        List<MsbarCode> records = new ArrayList<MsbarCode>();
        if (size > 0) {
            records = msbarCodeMapper.queryList(pager, condition);
        }
        pager.setRecords(records);
        pager.setTotalCount(size);
        return pager;
    }

    /**
     * 查询单条
     *
     * @param id
     * @return
     */
    @Override
    public MsbarCode findById(String id) {
        return msbarCodeMapper.queryById(id);
    }

    /**
     * 修改记录
     *
     * @param baseResource
     * @return
     */
    @Override
    public Resp update(MsbarCode msbarCode) {
        msbarCodeMapper.updateBySelect(msbarCode);
        return success();
    }

}
